package com.service.seedoctor.impl;

import com.comm.R;
import com.entity.PatientBank;
import com.entity.Registered;
import com.entity.SeeDoctor;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mapper.seedoctor.VisitsListMapper;
import com.service.seedoctor.VisitsListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitsListServiceImpl implements VisitsListService {

    @Autowired
    private VisitsListMapper visitsListMapper;
    @Override
    public R selectSeeDoctorListByNameAndDateRange(String startTime,String endTime,String bankName,int currentPage,int pageSize) {
        System.out.println("进来了2");
       R r=new R();
        try{
            System.out.println("进来了3");

            Page<SeeDoctor> ss= PageHelper.startPage(currentPage,pageSize);
                List<SeeDoctor> seeDoctors = visitsListMapper.selectSeeDoctorListByNameAndDateRange(startTime,endTime,bankName);
            for (SeeDoctor s : seeDoctors) {

                s.setRecordsRef(visitsListMapper.getPatientRecordsById(s.getRecordsId().intValue()));
                s.setPatientBankRef(visitsListMapper.getPatientBankById(s.getRecordsRef().getPersonalRecordsId()));

            }
                r.setMsg("查询成功");
                r.setCode(200);
                r.setData(seeDoctors);

        }catch (Exception e){
            e.printStackTrace();
            System.out.println("报错了");
            r.setMsg("服务器开小差");
            r.setCode(500);

        }
        return r;
    }

    @Override
    public R selectRegisteredListByNameAndDateRange(String startTime, String endTime, String bankName, int currentPage, int pageSize) {
        R r=new R();
        try{
            Page<Registered> p= PageHelper.startPage(currentPage,pageSize);
            List<Registered> registereds = visitsListMapper.selectRegisteredListByNameAndDateRange(startTime, endTime, bankName);
            for (Registered reg:registereds) {
                PatientBank pBank = visitsListMapper.getPatientBankById(reg.getPatientId());
                reg.setPatientBank(pBank);
            }
            r.setMsg("查询成功");
            r.setCode(200);
            r.setData(registereds);

        }catch (Exception e){
            e.printStackTrace();
            System.out.println("报错了");
            r.setMsg("服务器开小差");
            r.setCode(500);

        }
        return r;
    }
}
